﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZCRS.HCMS.Data;
using EZCRS.HCMS.Entity;
using System.Data;
using System.Data.SqlClient;

namespace EZCRS.HCMS.SqlClient
{
    public class sql_AdmScore
    {
        private string SqlStr = "";
        #region 常客消费记录列表
        public DataTable Score_List(string Uid)
        {
            if (Uid == "")
                return ExecSql.GetDataSet("select * from hfg_user_score ").Tables[0];
            else
                return ExecSql.GetDataSet("select * from hfg_user_score where uid=" + Uid).Tables[0];
        }
        #endregion
        #region 常客消费记录信息添加、修改
        /// <summary>
        /// 修改或添加常客消费记录信息
        /// </summary>
        /// <returns></returns>
        public bool Score_Add(string Uid, string Talyear, string Talbooktimes, string Talroomnights, string Talconsumenights, string Talhotelcount, decimal Talmount, string Talscore, string Talid)
        {
            SqlParameter[] pam = new SqlParameter[8];
            pam[0] = new SqlParameter("@uid", Uid);
            pam[1] = new SqlParameter("@talyear", Talyear);
            pam[2] = new SqlParameter("@talbooktimes", Talbooktimes);
            pam[3] = new SqlParameter("@talroomnights", Talroomnights);
            pam[4] = new SqlParameter("@talconsumenights", Talconsumenights);
            pam[5] = new SqlParameter("@talhotelcount", Talhotelcount);
            pam[6] = new SqlParameter("@talmount", Talmount);
            pam[7] = new SqlParameter("@talscore", Talscore);




            if (Talid != "")
                SqlStr = "update hfg_user_score set uid=@uid,talyear=@talyear,talbooktimes=@talbooktimes,talroomnights=@talroomnights,talconsumenights=@talconsumenights,talhotelcount=@talhotelcount,talmount=@talmount,talscore=@talscore where talid=" + Talid + "";
            else
                SqlStr = "insert into hfg_user_score(uid,talyear,talbooktimes,talroomnights,talconsumenights,talhotelcount,talmount,talscore) values(@uid,@talyear,@talbooktimes,@talroomnights,@talconsumenights,@talhotelcount,@talmount,@talscore)";
            if (ExecSql.SqlExecNoquery(SqlStr, pam) > 0)
                return true;
            else
                return false;
        }
        #endregion
        #region 常客消费记录Info数据的显示,显示一条数据
        public DataRow Score_Item(string Talid)
        {
            try
            {
                return ExecSql.GetDataSet("select * from hfg_user_score where talid=" + Talid).Tables[0].Rows[0];
            }
            catch
            {
                return null;
            }
        }
        #endregion
        #region 常客消费记录的删除
        public bool Score_Del(string Talid)
        {
            string sql = "", msg = "";
            sql = "delete from hfg_user_score where talid=" + Talid + "";
            if (ExecSql.SqlExecNoquery(sql) > 0)
                return true;
            else
                return false;
        }
        #endregion
        #region 消费记录统计
        public void userstat(int uid, int year)
        {
            SqlParameter[] pam = new SqlParameter[2];
            pam[0] = new SqlParameter("@uid", uid);
            pam[1] = new SqlParameter("@cyear", year);

            ExecSql.SqlExecNoqueryByProcedure("hfg_userscorestat", pam);
        }
        #endregion
    }
}
